package task;

import java.sql.SQLException;
import java.util.Map;

import org.eclipse.swt.graphics.ImageData;

import util.JdbcUtil;


public class ListTables extends DbTask {
	@Override
	protected void doRun(Map<String, String> props) throws SQLException {
		String schema = props.get("schema");
		System.out.printf("Number of tables in schema: '%s'%n", schema);
		if (dbType == DbType.ORACLE) { 
			try {
				System.out.printf("%s%n", JdbcUtil.getSingleString(conn(), String.format("select count(*) from all_tables where owner=upper('%s')", schema)));
			} catch (SQLException e1) {
				throw new RuntimeException(e1);
			}
		}
		System.out.printf("db url:%s, User:%s%n", conn().getMetaData().getURL(), conn().getMetaData().getUserName() );
		System.out.printf("Tables in schema '%s':%n", schema);
		String[] tables = getTablesInSchema(schema);
		for (String name : tables) {
			System.out.printf("  %s%n", name);
		}
	}


	@Override
	public String getDescription() {
		String desc = "List table names for a schema.";
		return desc;
	}

	@Override
	public ImageData getImageData() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String[] propertyNames() {
		String[] props = { "schema" };
		return props;
	}
}
